package com.roubsite.admin.action;

import com.roubsite.admin.dao.rsSystemLog.IRsSystemLogDao;
import com.roubsite.admin.dao.rsSystemLog.RsSystemLogDao;
import com.roubsite.database.annotation.Dao;
import com.roubsite.security.securityInfo.RSSecurityBaseUserInfo;
import com.roubsite.security.securityInfo.RSUserInfo;
import com.roubsite.utils.ClassBean;
import com.roubsite.utils.StringUtils;
import com.roubsite.web.action.RSAction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class AdminAction extends RSAction {
    protected RSUserInfo rSUserInfo;
    @Dao(dataSource = "dataSource", impl = RsSystemLogDao.class)
    IRsSystemLogDao rsSystemLogDao;

    @Override
    public boolean __init__(HttpServletRequest req, HttpServletResponse resp, ClassBean classBean) {
        RSSecurityBaseUserInfo rsSecUserInfo = (RSSecurityBaseUserInfo) getSession().getAttribute("rsSecUserInfo");
        rSUserInfo = new RSUserInfo(rsSecUserInfo);
        this.assign("rsUserInfo", rSUserInfo);
        try {
            rsSystemLogDao.insertLog(StringUtils.getIpAddr(request), rSUserInfo.getUid(), rSUserInfo.getUserName(), request.getServletPath(),
                    request.getServletPath() + "?" + (request.getQueryString()), request.getHeader("User-Agent"));
        } catch (Exception e) {
        }

        return true;
    }
}
